home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / ufexpand.zip / FEXPAND.ZIP / EXAMPLE2.C < prev    next >
C/C++ Source or Header  |  1993-03-03  |  3KB  |  117 lines

  1. #include <stdio.h>
  2. #include <memory.h>
  3. #include <stdlib.h>
  4. #include "fexpand.h"
  5.  
  6. /*
  7.  * File Template Expander - Example.
  8.  */
  9.  
  10. void main(int argc, char *argv[]);
  11. int Filter_It(char *p);
  12.  
  13. #ifndef TRUE
  14. #define TRUE 1
  15. #endif
  16.  
  17. #ifndef FALSE
  18. #define FALSE 0
  19. #endif
  20.  
  21.  
  22. void main(argc, argv)
  23. /****************************************************************************/
  24. /* This program takes the command line (argc/argv) and expands it using FTE */
  25. /* or it prompts for a string to be used instead.  See the usage section.   */
  26. /****************************************************************************/
  27. int argc;
  28. char *argv[];
  29. {
  30.     int i;
  31.  
  32.     int merge = FALSE, filter = FALSE, use_string = FALSE;
  33.     int new_argc;
  34.     char **new_argv;
  35.     char string[256];
  36.  
  37.     /*
  38.      * Look for command line switches.
  39.      */
  40.     for(i=0; i < argc; i++)
  41.     {
  42.         if (*argv[i] == '-')
  43.         {
  44.             if (*(argv[i]+1) == 'm')
  45.                 merge = TRUE;
  46.             else
  47.             if (*(argv[i]+1) == 'f')
  48.                 filter = TRUE;
  49.             else
  50.             if (*(argv[i]+1) == 's')
  51.                 use_string = TRUE;
  52.             else
  53.             {
  54.                 printf("Usage: example [-m] [-f] [-s] file_template1\n\t\t[file_template2 ... file_templateN]\n");
  55.                 printf("-m   Merge across all templates\n");
  56.                 printf("-f   Use the filter function\n");
  57.                 printf("-s   Prompt for a string instead of using argc/argv\n");
  58.                 exit(-1);
  59.             }
  60.         }
  61.     }
  62.  
  63.     /*
  64.      * String Functions
  65.      */
  66.     if (use_string)
  67.     {
  68.         printf("Enter string: ");
  69.         (void)gets(string);
  70.         if (filter)
  71.             new_argv = FileTemplateExpandFilterString(Filter_It, string,
  72.                                                       FALSE, merge, &new_argc);
  73.         else
  74.             new_argv = FileTemplateExpandString(string, FALSE, merge,
  75.                                                 &new_argc);
  76.     }
  77.  
  78.     /*
  79.      * Array Functions
  80.      */
  81.     else
  82.     {
  83.         if (filter)
  84.             new_argv = FileTemplateExpandFilter(Filter_It, argc, argv,
  85.                                                 TRUE, merge, &new_argc);
  86.         else
  87.             new_argv = FileTemplateExpand(argc, argv, TRUE, merge, &new_argc);
  88.     }
  89.  
  90.  
  91.     /*
  92.      * Print out the result.
  93.      */
  94.     for(i=0; i < new_argc; i++)
  95.         printf("%d\t\"%s\"\n", i, new_argv[i]);
  96.  
  97.     /*
  98.      * Free up the memory
  99.      */
  100.     for(i=0; i < new_argc; i++)
  101.         free(new_argv[i]);
  102.     free(new_argv);
  103. }
  104.  
  105.  
  106. /****************************************************************************/
  107. int Filter_It(char *p)
  108. /****************************************************************************/
  109. {
  110.     short int k;
  111.  
  112.     printf("Keep \"%s\" ", p);
  113.     scanf("%d", &k);
  114.  
  115.     return k;
  116. }
  117.